/**   
* @Title: CopyTextView.java 
* @author zengshuai shi   
* @date 2015年8月24日 下午5:17:47
*/
package com.onstar.cn.weight;

import android.widget.TextView;

import com.onstar.cn.common.util.CommonUtil;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnLongClickListener;

/**
 * 
* @ClassName: CopyTextView 
* @Description: 可复制的TextView
* @author zengshuai shi
* @date 2015年8月24日 下午5:17:47
 */
public class CopyTextView extends TextView implements OnLongClickListener{
	public String[] strs = new String[] { getContext().getResources().getString(R.string.text_copy) };

	public CopyTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.setOnLongClickListener(this);
	}

	public CopyTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.setOnLongClickListener(this);
	}

	public CopyTextView(Context context) {
		super(context);
		this.setOnLongClickListener(this);
	}


	@Override
	public boolean onLongClick(View v) {
		AlertDialog.Builder builder = new Builder(getContext());
		builder.setItems(strs, new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				CommonUtil.copy(CopyTextView.this.getText().toString(), getContext());
			}
		});
		builder.create().show();

		return false;
	}
}
